package com.ruoyi.system.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.ruoyi.common.core.domain.entity.Comment;
import com.ruoyi.system.mapper.CommentDao;
import com.ruoyi.system.service.CommentService;
import org.springframework.stereotype.Service;

/**
 * Auto created by codeAppend plugin
 */
@Service
public class CommentServiceImpl extends ServiceImpl<CommentDao, Comment> implements CommentService {
    @Override
    public boolean saveComment(Comment comment) {
        Comment c = new Comment();
        c.setScenicId(comment.getScenicId());
        c.setUserId(comment.getUserId());
        c.setComment(comment.getComment());
        c.setImage(comment.getImage());
        c.setDatetime(comment.getDatetime());
        c.setAuditor(comment.getAuditor());
        c.setStatus(comment.getStatus());
        c.setMsg(comment.getMsg());
        return baseMapper.insert(c) > 0;
    }

    @Override
    public boolean deleteCommentById(Long id) {
        return baseMapper.deleteById(id) > 0;
    }

    @Override
    public boolean updateComment(Comment comment) {
        LambdaQueryWrapper<Comment> lqw = new LambdaQueryWrapper<>();
        lqw.eq(Comment::getId, comment.getId());
        Comment c =baseMapper.selectOne(lqw);
        if (c == null){
            throw new RuntimeException("Comment not found");
        }
        return false;
    }

    @Override
    public Comment getCommentById(Long id) {
        return null;
    }

    // use "baseMapper" to call jdbc
    // example: baseMapper.insert(entity);
    // example: baseMapper.selectByPage(params);

}
